//
//  SUNNavigtionController.swift
//  SUNweibo
//
//  Created by sighting on 16/8/20.
//  Copyright © 2016年 sighting. All rights reserved.
//

import UIKit

class SUNNavigtionController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBar.isHidden = true
    }
    
    // 重写pushViewController方法,隐藏BottomBar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        
        // 如果不是栈顶控制器就隐藏BottomBar
        if childViewControllers.count > 0 {

            viewController.hidesBottomBarWhenPushed = true
         
            if let vc = viewController as? SUNBaseViewController {

                var title = "返回"
                
                if childViewControllers.count == 1{
                    
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popBack), isBack: true)
            }
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func popBack(){
    
    popViewController(animated: true)
    
    }
}
